package com.lg.erp.service.impl.zhangchaofu;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lg.erp.entity.zhangchaofu.ZCFTWare;
import com.lg.erp.entity.zhangchaofu.TWarning;
import com.lg.erp.mapper.zhangchaofu.StockEarlyWarningMapper;
import com.lg.erp.service.zhangchaofu.StockEarlyWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockEarlyWarningServiceImpl extends ServiceImpl<StockEarlyWarningMapper, TWarning> implements StockEarlyWarningService {

    @Autowired
    private StockEarlyWarningMapper stockEarlyWarningMapper;

    @Override
    public List<ZCFTWare> findStockEarlyWarningWareAndWarehouse() {
        List<ZCFTWare> stockEarlyWarningWareAndWarehouse = stockEarlyWarningMapper.findStockEarlyWarningWareAndWarehouse();
        //修改label,el_tree
        for (int i = 0; i < stockEarlyWarningWareAndWarehouse.size(); i++) {
            for (int j = 0; j < stockEarlyWarningWareAndWarehouse.get(i).getCargoAreaList().size(); j++) {
                stockEarlyWarningWareAndWarehouse.get(i).getCargoAreaList().get(j).setWareName(stockEarlyWarningWareAndWarehouse.get(i).getCargoAreaList().get(j).getGoodsName());
            }
        }
        return stockEarlyWarningWareAndWarehouse ;
    }

    @Override
    public IPage<TWarning> findStockEarlyWarningMessageProductPage(Page<TWarning> page) {
        return stockEarlyWarningMapper.findStockEarlyWarningMessageProductPage(page);
    }

    @Override
    public void modifyStockEarlyWarningMessageProduct(TWarning warning) {
        stockEarlyWarningMapper.update(warning,new QueryWrapper<TWarning>().lambda()
                .eq(TWarning::getProductId,warning.getProductNumber())
                .eq(TWarning::getWarehouseId,warning.getWarehouseId())
        );
    }

    @Override
    public List<TWarning> findStockEarlyWarningMessageProduct(String productName) {
        return stockEarlyWarningMapper.findStockEarlyWarningMessageProduct(productName);
    }

    @Override
    public List<TWarning> findStockEarlyWarningMessageWareProduct(String wareId) {
        return stockEarlyWarningMapper.findStockEarlyWarningMessageWareProduct(wareId);
    }
}
